import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
public class Ticket {
    private String ticketId;
    private String showId;
    private Seat seat;
    private double price;
    private Date sellTime;
    private int status;
    private String seller;

    public Ticket(String showId, Seat seat, double price, String seller) {
        this.ticketId = generateTicketId();
        this.showId = showId;
        this.seat = seat;
        this.price = price;
        this.sellTime = new Date();
        this.status = 0;
        this.seller = seller;
    }
    private String generateTicketId() {
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
        String timeSuffix = String.valueOf(System.currentTimeMillis()).substring(8);
        return "TICKET_" + uuid + timeSuffix;
    }

    public boolean refund() {
        if (status == 1) {
            return false;
        }
        status = 1;
        return true;
    }
    public void printTicketInfo(Show show) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        System.out.println("\n====================电影票====================");
        System.out.println("电子票号：" + ticketId);
        System.out.println("影片名称：" + show.getMovie().getName());
        System.out.println("放映时间：" + sdf.format(show.getShowTime()));
        System.out.println("放映厅：" + show.getHall().getHallName());
        System.out.println("座位：" + seat.getRow() + "排" + seat.getCol() + "座");
        System.out.println("票价：" + price + "元");
        System.out.println("售票时间：" + sdf.format(sellTime));
        System.out.println("售票员：" + seller);
        System.out.println("状态：" + (status == 0 ? "正常" : "已退票"));
        System.out.println("=============================================");
    }
    public String getTicketId() {
        return ticketId;
    }
    public String getShowId() {
        return showId;
    }
    public Seat getSeat() {
        return seat;
    }
    public double getPrice() {
        return price;
    }
    public Date getSellTime() {
        return sellTime;
    }
    public int getStatus() {
        return status;
    }
    public String getSeller() {
        return seller;
    }
}
